package view;

import controller.AddBookListener;
import controller.AddUserListener;
import pojo.Book;
import pojo.User;

import javax.swing.*;
import java.awt.*;

public class AddUser extends JDialog {
    private JLabel labelId, labelPW, labelName, labelGender, labelPN, labelType;
    //文本框
    JTextField tfNum, tfPN, tfName, tfGender, tfType;
    //密码
    JPasswordField tfPwd;
    private User user;
    private AddUserListener listener;
    private JComboBox cBType;
    private UserView userView;
    public AddUser(UserView userView) {
        this.userView=userView;
        listener = new AddUserListener(this,userView);
        this.setTitle("新增用户");
        this.setSize(400, 500);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setLayout(new BorderLayout());
        this.add(this.getPanel(), BorderLayout.CENTER);
        this.add(this.getButton(), BorderLayout.SOUTH);

    }

    public JPanel getPanel() {
        JPanel jPanel = new JPanel();
        jPanel.setLayout(new GridLayout(6, 2));
        labelId = new JLabel("                           学号:");
        labelPW = new JLabel("                           密码:");
        labelName = new JLabel("                           姓名:");
        labelGender = new JLabel("                           年级:");
        labelPN = new JLabel("                           电话:");
        labelType = new JLabel("                           类别");
        tfNum = new JTextField(15);
        tfPwd = new JPasswordField(15);
        tfName = new JTextField(15);
        tfGender = new JTextField(15);
        tfPN = new JTextField(15);
        cBType=new JComboBox();    //创建JComboBox
        cBType.addItem("--请选择--");    //向下拉列表中添加一项
        cBType.addItem("系统管理员");
        cBType.addItem("图书管理员");
        cBType.addItem("普通用户");

        jPanel.add(labelId);
        jPanel.add(tfNum);

        jPanel.add(labelPW);
        jPanel.add(tfPwd);

        jPanel.add(labelName);
        jPanel.add(tfName);

        jPanel.add(labelGender);
        jPanel.add(tfGender);

        jPanel.add(labelPN);
        jPanel.add(tfPN);

        jPanel.add(labelType);
        jPanel.add(cBType);

        return jPanel;
    }

    public JPanel getButton() {
        JButton jButton = new JButton("新增");
        JButton jButton1 = new JButton("返回");
        jButton.addActionListener(listener);
        jButton1.addActionListener(listener);
        JPanel jPanel = new JPanel();
        jPanel.add(jButton);
        jPanel.add(jButton1);
        return jPanel;
    }

    public JLabel getLabelId() {
        return labelId;
    }

    public JTextField getTfNum() {
        return tfNum;
    }

    public JTextField getTfPN() {
        return tfPN;
    }

    public JTextField getTfName() {
        return tfName;
    }

    public JTextField getTfGender() {
        return tfGender;
    }

    public JTextField getTfType() {
        return tfType;
    }

    public JPasswordField getTfPwd() {
        return tfPwd;
    }

    public JComboBox getCBType() {
        return cBType;
    }
}